package com.yequan.hbb.view.fragment.loginfragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputEditText;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.yequan.hbb.R;
import com.yequan.hbb.app.MyApplication;

/**
 * A simple {@link Fragment} subclass.
 */
public class LoginFragment extends Fragment implements View.OnClickListener {

    public final static int LOGIN=0;
    private TextInputEditText phoneEdit;
    private TextInputEditText passwordEdit;
    private Button loginButton;
    private String userPhone;
    private String userPassword;
    public LoginFragment() {}


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_login, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        MyApplication.level=LOGIN;
        phoneEdit= (TextInputEditText) view.findViewById(R.id.login_account);
        passwordEdit= (TextInputEditText) view.findViewById(R.id.login_password);
        loginButton= (Button) view.findViewById(R.id.login_btn);
        loginButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        userPhone=phoneEdit.getText().toString().trim();
        userPassword=passwordEdit.getText().toString().trim();
        if (TextUtils.isEmpty(userPhone)||TextUtils.isEmpty(userPassword)){
            if (TextUtils.isEmpty(userPhone)){
                phoneEdit.setError("手机号码不能为空");
            }
            if (TextUtils.isEmpty(userPassword)){
                passwordEdit.setError("密码不能为空");
            }
        } else {
            Toast.makeText(getContext(), "登录成功", Toast.LENGTH_SHORT).show();
        }
    }
}
